﻿using System;
using System.Collections.Generic;
using System.Text;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.DataUpdater;

namespace AgencyManagerSystem.Core
{
    public abstract class BaseUpdaterCreator<T> where T:DBModel
    {
        protected void FlagAndApproveFlagValid(BaseUpdater<T> sender, DataUpdatingEventArgs<T> e)
        {
            if(e.Insert==null)
            {
                return;
            }
            if(e.Insert.AutoId==0&&e.Insert.Flag!=0)
            {
                e.Cancel = true;
                e.Message = "新创建的档案，其Flag必须为初始值";
            }
            if(e.Delete==null&&e.Insert.AutoId!=0)
            {
                e.Cancel = true;
                e.Message = "资料已被其他用户移除";
            }
            if(e.Insert.AutoId!=0&&e.Insert.Flag!=e.Delete.Flag)
            {
                e.Cancel = true;
                e.Message = "资料已被其他用户变更";
            }
            if(e.Delete!=null)
            {
                if(e.Delete.ApproveFlag!= e.Insert.ApproveFlag)
                {
                    e.Cancel = true;
                    e.Message = "审核码不能由更新程序修改";
                }
            }
        }
    }
}
